package com.gxa.scdx.cloud.user.controller;

import com.gxa.scdx.cloud.user.pojo.Device;
import com.gxa.scdx.cloud.user.service.DeviceService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 设备表控制层
 *
 * @author 颜可翔
 * @version 1.0
 */

@RestController
@RequestMapping("/device")
@Api(value = "设备管理",tags = "设备管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})

public class DeviceController {
    @Resource
    private DeviceService deviceService;


    /**
     * 通过主键查询单条数据
     * @param userId
     * @return 单条数据
     */
    @RequestMapping(value = "/selectByUserId", method = RequestMethod.GET)
    @ApiOperation(value = "查询设备",notes = "查询设备",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户ID",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> selectByUserId(@RequestParam(value = "userId",required = true) int userId) {
        return this.deviceService.selectByUserId(userId);
    }


    /**
     * 通过主键查询所有数据
     * @return 数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询设备",notes = "查询设备",httpMethod = "GET")
    public Map<String, Object> selectAll() {
        return this.deviceService.selectAll();
    }

    /**
     * 插入数据
     * @return 是否成功
     */
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    @ApiOperation(value = "查询设备",notes = "查询设备",httpMethod = "POST")
    public Map<String, Object> insert(@RequestBody  Device device) {
        return this.deviceService.insert(device);
    }

    /**
     * 设备id获取数据
     * @return 数据
     */
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    @ApiOperation(value = "查询设备",notes = "查询设备",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uuid",value = "设备ID",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> selectById(@RequestParam(value = "uuid",required = true) String uuid) {
        return this.deviceService.selectById(uuid);
    }

    /**
     * 设备数量
     * @return 数据
     */
    @RequestMapping(value = "/count", method = RequestMethod.GET)
    @ApiOperation(value = "查询设备数量",notes = "查询设备数量",httpMethod = "GET")
    public Map<String, Object> count( ) {
        return this.deviceService.count();
    }


}
